import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/common/user_helper.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:flutter_learn_vi/src/utils/navigator_utils.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

import '../../bean/bean_train.dart';
import '../common/location_page.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/11.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class DirectorTeacherWorkLogAddPage extends StatefulWidget {
  final TrainBean trainBean;

  const DirectorTeacherWorkLogAddPage({Key key, this.trainBean})
      : super(key: key);

  @override
  _DirectorTeacherWorkLogAddPageState createState() =>
      _DirectorTeacherWorkLogAddPageState();
}

class _DirectorTeacherWorkLogAddPageState
    extends State<DirectorTeacherWorkLogAddPage> {
  TextEditingController _editingController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("添加工作日志"),
      ),

      ///填充布局
      body: Container(
          color: Colors.white,
          width: double.infinity,
          padding: EdgeInsets.only(bottom: 20),
          child: Column(
            children: [
              HomeLocationWidget(
                pageTag: widget.trainBean.trainId.toString(),
                isAdCode: true,
              ),
              Container(
                padding: EdgeInsets.all(12),
                child: TextField(
                  controller: _editingController,
                  maxLength: 200,
                  maxLines: 8,
                  style: TextStyle(),
                  decoration: InputDecoration(
                      hintText: "请输入您的工作日志信息", border: OutlineInputBorder()),
                ),
              ),
              Align(
                child: Container(
                  width: 100,
                  margin: EdgeInsets.only(right: 12),
                  child: ElevatedButton(
                    onPressed: () {
                      String text = _editingController.text;
                      if (text.length == 0) {
                        ToastUtils.showToast("请输入工作日志");
                        return;
                      }
                      commitNetDataFunction(text);
                    },
                    child: Text("提交"),
                  ),
                ),
                alignment: Alignment.centerRight,
              ),
            ],
          )),
    );
  }

  void commitNetDataFunction(String text) async {
    Map<String, dynamic> map = {
      "workContent": text,
      "trainName": widget.trainBean.trainName,
      "trainId": widget.trainBean.trainId,
      "currentWeatherInfo": UserHelper.getInstance.currentWeatherInfo,
    };
    String url = HttpHelper.workLogAdd;
    ResponseInfo partResponseInfo = await DioUtils.instance.postRequest(
      url: url,
      jsonMap: map,
    );
    if (partResponseInfo.success) {
      ToastUtils.showToast("提交成功");
    } else {
      ToastUtils.showToast("提交失败 ${partResponseInfo.message}");
      return;
    }
    Future.delayed(Duration(milliseconds: 1200), () {
      NavigatorUtils.pop(context);
    });
  }
}
